package com.example.a7822.myapplication.shopcart.common;


import com.example.a7822.myapplication.shopcart.beans.ShopBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by 洪坤峰 on 2017/1/11.
 */

public class ShopJsonUtils {//TODO 根据接口情况修改解析结果

    public static ShopBean readJSONShopBean(final String res) {
        ShopBean shop = new ShopBean();

        try {
            JSONObject json = new JSONObject(res);
            JSONObject shopinfo = json.getJSONObject("shopInfo");
            JSONArray jsonArrayPhptos = shopinfo.getJSONArray("shopPicture");
            String picUrl = jsonArrayPhptos.getString(0);

            shop.setFavorite(false);//TODO 关注店铺缺少接口
            shop.setImageUrl(shopinfo.getString("shopLogo"));
            shop.setShopName(shopinfo.getString("shopName"));
            shop.setShopDetail("");
            shop.setShopPicUrl(picUrl);
            shop.setShopRate(shopinfo.getInt("shopGrade") * 2);
            shop.setShopBrief(shopinfo.getString("ShopBrief"));
            shop.setShopId(shopinfo.getInt("id"));
            shop.setShopDistance("6");//TODO 缺少店铺距离
            shop.setType(0);
//            PinYin.getPinYin(shop.getShopName(),shop.getPinyinElement());
//                            ShopManager.getInstance().getShopModelList().add(shop);
//                            EventBus.getDefault().postSticky(ShopEvent.MAIN_DATA_OK);
            return shop;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return shop;
    }


}
